home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / cug232 / acollect.st next >
Text File  |  1987-06-17  |  2KB  |  71 lines

  1. Class ArrayedCollection :SequenceableCollection
  2. | current |
  3. [
  4.        = anArray                       | i |
  5.                 (self size ~= anArray size) ifTrue: [^ false].
  6.                 i <- 0.
  7.                 self do: [:x | (x ~= (anArray at: (i <- i + 1)))
  8.                                 ifTrue: [^ false]].
  9.         ^ true
  10. |
  11.         at: key ifAbsent: exceptionBlock
  12.         ((key <= 0) or: [key > self size])
  13.             ifTrue: [^ exceptionBlock value].
  14.                 ^ self at: key
  15. |
  16.     coerce: aCollection        | temp |
  17.         temp <- self class new: aCollection size.
  18.         temp replaceFrom: 1 to: aCollection size with: aCollection.
  19.         ^ temp
  20. |
  21.        copyFrom: start to: stop                | size temp |
  22.         size <- stop - start + 1.
  23.         temp <- self class new: size.
  24.         temp replaceFrom: 1 to: size with: self startingAt: start.
  25.         ^ temp
  26. |
  27.         currentKey
  28.                 ^ current
  29. |
  30.     deepCopy        | newobj |
  31.         newobj <- self class new: self size.
  32.         (1 to: self size) do:
  33.             [:i | newobj at: i
  34.                 put: (self at: i) copy ].
  35.         ^ newobj
  36. |
  37.        do: aBlock
  38.                 (1 to: self size)
  39.             do: [:i | current <- i.
  40.                 aBlock value: (self at: i)]
  41. |
  42.        first
  43.                 current <- 1.
  44.                 ^ (current <= self size)
  45.             ifTrue: [ self at: current]
  46. |
  47.     firstKey
  48.         ^ 1
  49. |
  50.     lastKey
  51.         ^ self size
  52. |
  53.     next
  54.                 current <- current + 1.
  55.                 ^ (current <= self size)
  56.             ifTrue: [ self at: current]
  57. |
  58.     padTo: length
  59.         ^ (self size < length)
  60.             ifTrue: [ self ,
  61.                 (self class new: (length - self size) ) ]
  62.             ifFalse: [ self ]
  63. |
  64.     shallowCopy        | newobj |
  65.         newobj <- self class new: self size.
  66.         (1 to: self size) do:
  67.             [:i | newobj at: i
  68.                 put: (self at: i) ].
  69.         ^ newobj
  70. ]
  71.